package com.chanceit.ssss.dialog;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;

public class DateTimePickerDialog {
	TextView tv;
	DatePickerDialog dateDialog;
	TimePickerDialog timeDialog;
	String date ;
	boolean isTimeDialog = false;
	public DateTimePickerDialog(final Context context, final TextView tv) {
		tv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (dateDialog == null) {

					Calendar c = Calendar.getInstance();
					dateDialog = new DatePickerDialog(context,
							new DatePickerDialog.OnDateSetListener() {
								@Override
								public void onDateSet(DatePicker dp, int year,
										int month, int dayOfMonth) {
									date = year + "-" + (month + 1) + "-"
											+ dayOfMonth + " ";
									Calendar time = Calendar.getInstance();
									if (timeDialog ==null&&!isTimeDialog) {
										 timeDialog = new TimePickerDialog(
													context,
													new TimePickerDialog.OnTimeSetListener() {
														@Override
														public void onTimeSet(
																TimePicker tp,
																int hourOfDay,
																int minute) {
															tv.setText(date+hourOfDay + ":"
																	+ minute+":"+"00");
															isTimeDialog = false;
														}
													}, time.get(Calendar.HOUR_OF_DAY),
													time.get(Calendar.MINUTE), true);
											timeDialog.setTitle("TimePicker");
									}
									timeDialog.show();
									isTimeDialog = true;

								}
							}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c
									.get(Calendar.DAY_OF_MONTH));
					dateDialog.setTitle("DatePicker");

				}
				dateDialog.show();

			}
		});
	}
}
